package com.ljh.account.controller;

import com.ljh.account.dao.Category;
import com.ljh.account.service.CategoryService;
import com.ljh.account.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/category/list")
    public Response category(){
        List<Category> allCategories = categoryService.getAllCategories();
        return Response.success(allCategories);
    }

    @PostMapping("/admin/category")
    public Response category(@RequestBody Category category){
        categoryService.addCategory(category);
        return Response.success("新增分类成功!");
    }

    @DeleteMapping("/admin/category")
    public Response category(@RequestParam int id){
        categoryService.deleteCategory(id);
    return Response.success("分类删除成功！");
    }
}
